package com.huyong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huyong.dao.UserDao;
import com.huyong.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements com.huyong.service.UserService {
    @Autowired
    private UserDao userDao;
    //查询所有用户
    @Override
    public List findAll(){
        List list = userDao.selectList(null);
        return list;
    }
    //删除一个用户
    @Override
    public boolean deleteUser(Long studyCode){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("studyCode",studyCode);
        int result = userDao.delete(wrapper);
        return result==1?true:false;
    }

    //添加用户
    @Override
    public boolean addUser(User user){
        int result = userDao.insert(user);
        return result==1?true:false;
    }

    //查找一个用户信息
    @Override
    public User findOne(int id) {
        return userDao.selectById(id);
    }

    //修改用户信息
    public boolean updateUser(User user){
        User updateUser = userDao.selectById(user.getId());
        updateUser = user;
        int result = userDao.updateById(updateUser);
        return result==1?true:false;
    }
}
